<?php
/**
 * 功能： json输出数据
 * 说明：
 * 创建日期：
 * 更新日期：
 * 作者：Mirze
 * 补充说明： 
 * 
 */
require_once('TheAdmin.class.php');
$admin = new TheAdmin();


$opt = isset($_GET['opt']) ? intval($_GET['opt']) : 0;
$_search = ("true" ==trim($_GET['_search'])) ? true : false;

///*
if($_search) {
	$opt = 2; //
	$searchField = isset($_GET['searchField']) ? trim($_GET['searchField']) : '';
	if(!empty($searchField)) {
		$searchString = isset($_GET['searchString']) ? trim($_GET['searchString']) : '';
	}
	
}
//*/

$data['list_data'][0] = array(
	'id' => 1,
	'userName' => 'json userName',
	'invdate' => '2011-12-02',
	'amount' => 'A01',
	'tax' => 'Mirze',
	'total' => '6',
	'note' => 'Test'
);
$data['list_data'][1] = $data['list_data'][0];
$data['list_data'][1]['id'] = 2;
$data['list_data'][1]['userName'] = 'two';

$data['list_data'][2] = $data['list_data'][0];
$data['list_data'][2]['id'] = 3;
$data['list_data'][2]['userName'] = 'three';

$data['page'] = 1;
$data['total'] = 1;
$data['records'] = 3;

//dump($data);

switch($opt) {
	case '1':
		$data['list_data'][0]['userName'] = 'edit name';
		echo json_encode($data);	
	    break;
	case '2': //search
		$key = ($searchString>1) ? $searchString-1 : 0;
		$temp['list_data'][0] = $data['list_data'][$key];
		$temp['page'] = 1;
		$temp['total'] = 1;
		$temp['records'] = 10;
		echo json_encode($temp);	
	    break;
	default:
		echo json_encode($data);
		break;
}

$json = '{"totalpages":"3","currpage":"1","totalrecords":"11","griddata":[{"SalesReasonID":"1","Name":"Price","ReasonType":"Other","ModifiedDate":"1998年6月1日"},{"SalesReasonID":"2","Name":"On Promotion","ReasonType":"Promotion","ModifiedDate":"1998年6月1日"},{"SalesReasonID":"3","Name":"Magazine Advertisement","ReasonType":"Marketing","ModifiedDate":"1998年6月1日"},{"SalesReasonID":"4","Name":"Television Advertisement","ReasonType":"Marketing","ModifiedDate":"1998年6月1日"},{"SalesReasonID":"5","Name":"Manufacturer","ReasonType":"Other","ModifiedDate":"1998年6月1日"}]}';

//echo $json;